import type { MsgInfo } from '#/api/agent/model/conversation';
import type { listType } from '#/store/agentchat';

/**
 *
 * @param sender   1-客服 2-顾客 3-AI
 * @param id
 * @param content  内容
 * @param readedAt 已读时间抽
 */
export const BubbleListItemConfig = (
  sender: number,
  id: number,
  content: string,
  trans: string,
  readedAt: number,
  status: number,
  time: string,
  image?: string[],
): listType => {
  return {
    id: id as unknown as string,
    key: id,
    content: content || '',
    trans: trans || '',
    loading: false,
    readedAt,
    image,
    status,
    shape: 'corner',
    role: sender === 1 ? 'user' : 'ai',
    placement: sender === 1 ? 'end' : 'start',
    variant: sender === 1 ? 'filled' : 'outlined',
    isMarkdown: false,
    typing: true,
    isFog: false,
    time,
    avatar:
      sender === 1
        ? 'https://avatars.githubusercontent.com/u/76239030?v=4'
        : 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    avatarSize: '50px',
    avatarGap: '12px',
  };
};

export const BubbleListItemHandle = (Data: MsgInfo[]): listType[] => {
  const data = Data.map((item: MsgInfo) => ({
    id: item.id,
    key: item.id,
    content: item?.contJson?.text?.body || '',
    trans: item?.contJson?.text?.trans || '',
    loading: false,
    readedAt: item.readedAt,
    image: item?.contJson?.image?.link,
    status: item.status,
    shape: 'corner',
    role: item.sender === 1 ? 'user' : 'ai',
    placement: item.sender === 1 ? 'end' : 'start',
    variant: item.sender === 1 ? 'filled' : 'outlined',
    isMarkdown: false,
    typing: true,
    isFog: false,
    time: item.createdAt,
    avatar:
      item.sender === 1
        ? 'https://avatars.githubusercontent.com/u/76239030?v=4'
        : 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
    avatarSize: '50px',
    avatarGap: '12px',
  }));
  return data as unknown as listType[];
};
